class Solution:
    def thirdMax(self, nums: list) -> int:
        nums = list(set(nums))
        nums.sort(reverse=True)
        try:
            return nums[2]
        except:
            return nums[-1]